﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using LY.Entity;
using LY.Entity.PageSearch;
using LY.Entity.SearchEntity;
using LY.Entity.Entities;

namespace LY.DataAccess.Repository
{
    public class BlackMemberRepository : BaseRepository
    {
      //查询出所有的黑名单用户
//      public List<U_BlackMember> SelectBlackMember() {
//          string sql = @"SELECT [ID]
//                      ,[MemberID]
//                      ,[AddedTime]
//                      ,[Remark]
//                      FROM [zhongchou].[dbo].[U_BlackMember]";
//          return base.Query<U_BlackMember>(sql, null);
//      }
        //删除黑名单
      public int DeleteBlackMember(int id)
      {
          string sql = "delete from U_BlackMember where MemberID=@ID";
          return base.Excute(sql, new {ID=id });
      }
        //添加黑名单
      public long AddBlackMember(U_BlackMember blackMember)
      {
          //string sql = "insert into U_BlackMember values('')";
         return base.Insert(blackMember);
      }
      //查询列表
      public PagedList<U_BlackMember_EX> QueryBlackMemberList(BlackMemberSearch search, PageView view)
      {
          string cols = @" b.[ID]
                          ,b.[MemberID]
                          ,Name
                          ,b.[AddedTime]
                          ,[Remark]";
          string sqlWhere = "";
          if (!string.IsNullOrEmpty(search.AddedTime))
          {
              sqlWhere += "AND convert(varchar,[AddedTime],120) like '%" + search.AddedTime + "%'";
          }
          //return base.PageGet<C_Menu>(view, cols, @" [C_Menu]", sqlWhere, " [Sequence]", "");
          return base.PageGet<U_BlackMember_EX>(view, cols, @" [zhongchou].[dbo].[U_BlackMember] b left join U_Member m on b.MemberID=m.ID  ", sqlWhere, "b.[Id] ASC", "");
      }
        //根据ID查询单个实体对象
      public U_BlackMember getBlackMember(int? id) {
          string sql = @"SELECT [ID]
                      ,[MemberID]
                      ,[AddedTime]
                      ,[Remark]
                      FROM [zhongchou].[dbo].[U_BlackMember] where ID=@ID";
          return base.Get<U_BlackMember>(sql, new { ID = id });
      }

      //修改黑名单
      public int UpdateBlackMember(U_BlackMember blackMember)
      {
          return base.Update(blackMember);
      }
    
        //修改会员状态
      public int updateMemberStatus(U_Member member) {
          return base.Update(member);
      }
    }
}
